package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.EntPic;

import java.util.ArrayList;


public class EntInfoPicDetailActivity extends Activity {


    private int position = 0;
    private ArrayList<EntPic> picBeenList;
    private TextView tv_time;
    private TextView tv_location;
    private TextView tv_addr;
    private ImageView iv_pic;
    private RelativeLayout rl_back;
    private LinearLayout ll_up;
    private LinearLayout ll_next;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ent_info_pic_detail);

        tv_time = findViewById(R.id.tv_time);
        tv_location = findViewById(R.id.tv_location);
        tv_addr = findViewById(R.id.tv_addr);
        iv_pic = findViewById(R.id.iv_pic);
        rl_back = findViewById(R.id.rl_back);
        rl_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ll_up = findViewById(R.id.ll_up);
        ll_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position == 0) {
                    Toast.makeText(EntInfoPicDetailActivity.this, "当前为第一张", Toast.LENGTH_SHORT).show();
                } else {
                    position--;
                    if (picBeenList.get(position).getCreate_time() == null || picBeenList.get(position).getCreate_time().isEmpty()) {
                        tv_time.setText("");
                    } else {
                        tv_time.setText(picBeenList.get(position).getCreate_time());
                    }

                    if (picBeenList.get(position).getCreate_longitude() == null || picBeenList.get(position).getCreate_longitude() == 0f) {
                        tv_location.setText("");
                    } else {
                        tv_location.setText(picBeenList.get(position).getCreate_longitude() + "  " + picBeenList.get(position).getCreate_latitude());
                    }

                    if (picBeenList.get(position).getAddr() == null || picBeenList.get(position).getAddr().isEmpty()) {
                        tv_addr.setText("");
                    } else {
                        tv_addr.setText(picBeenList.get(position).getAddr());
                    }
                    Glide.with(EntInfoPicDetailActivity.this)
                            .load(InitApplication.BASE_URL_ENT_PIC+picBeenList.get(position).getPath())
                            .error(R.drawable.loading).placeholder(R.drawable.loading)
                            .into(iv_pic);
                }

            }
        });
        ll_next = findViewById(R.id.ll_next);
        ll_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position == picBeenList.size() - 1) {
                    Toast.makeText(EntInfoPicDetailActivity.this, "当前为最后一张", Toast.LENGTH_SHORT).show();
                } else {
                    position++;
                    if (picBeenList.get(position).getCreate_time() == null || picBeenList.get(position).getCreate_time().isEmpty()) {
                        tv_time.setText("");
                    } else {
                        tv_time.setText(picBeenList.get(position).getCreate_time());
                    }

                    if (picBeenList.get(position).getCreate_longitude() == null || picBeenList.get(position).getCreate_longitude() == 0f) {
                        tv_location.setText("");
                    } else {
                        tv_location.setText(picBeenList.get(position).getCreate_longitude() + "  " + picBeenList.get(position).getCreate_latitude());
                    }

                    if (picBeenList.get(position).getAddr() == null || picBeenList.get(position).getAddr().isEmpty()) {
                        tv_addr.setText("");
                    } else {
                        tv_addr.setText(picBeenList.get(position).getAddr());
                    }
                    Glide.with(EntInfoPicDetailActivity.this)
                            .load(InitApplication.BASE_URL_ENT_PIC+picBeenList.get(position).getPath())
                            .error(R.drawable.loading).placeholder(R.drawable.loading)
                            .into(iv_pic);
                }
            }
        });


        position = getIntent().getIntExtra("position", 0);
        picBeenList = (ArrayList<EntPic>) getIntent().getSerializableExtra("list");
        if (picBeenList.get(position).getCreate_time() == null || picBeenList.get(position).getCreate_time().isEmpty()) {
            tv_time.setText("");
        } else {
            tv_time.setText(picBeenList.get(position).getCreate_time());
        }

        if (picBeenList.get(position).getCreate_longitude() == null || picBeenList.get(position).getCreate_longitude() == 0f) {
            tv_location.setText("");
        } else {
            tv_location.setText(picBeenList.get(position).getCreate_longitude() + "  " + picBeenList.get(position).getCreate_latitude());
        }

        if (picBeenList.get(position).getAddr() == null || picBeenList.get(position).getAddr().isEmpty()) {
            tv_addr.setText("");
        } else {
            tv_addr.setText(picBeenList.get(position).getAddr());
        }
        Glide.with(EntInfoPicDetailActivity.this)
                .load(InitApplication.BASE_URL_ENT_PIC+picBeenList.get(position).getPath())
                .error(R.drawable.loading).placeholder(R.drawable.loading)
                .into(iv_pic);
    }
}
